package cn.zymall.order.mq;

import cn.zymall.common.listen.BaseAMQPListen;
import cn.zymall.common.model.Order;
import cn.zymall.order.service.OrderService;
import com.google.gson.Gson;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: mall
 * @description: 订单队列监听
 * @author: YueNiao
 * @email: 1486617253@qq.com
 * @create: 2020-08-19 16:22
 **/
/*@Component
@RabbitListener(queues = "orders")*/
public class OrderListen implements BaseAMQPListen{
	@Autowired
	OrderService orderService;
	@Override
	@RabbitHandler
	public void listenMsg(String msg){
		try{
			Gson gson = new Gson();
			Order order = gson.fromJson(msg, Order.class);
			orderService.decrementProductStore(order);
		}catch (Exception e){
			e.printStackTrace();
		}

	}
}
